//function changeCode() {
//
//	fcodeImg.src = httpAdress + "/servlet/validateCodeServlet?t=" + genTimestamp();
//
//}
//时间戳函数
//function genTimestamp() {
//	var time = new Date();
//	return time.getTime();
//
//}
//60秒倒计时
function mtime(na){
	var num=60;
 var ff=setInterval(function(){
		num--;
		na.disabled=true;
		na.innerHTML=num+'s后尝试';
		na.style.background='gray';
		
		if(num==0){
			clearInterval(ff);
			na.disabled=false;
			na.innerHTML='获取验证码';
		na.style.background='#F26100';
		}
	},1000)
}


	var fcodeImg = document.getElementById("fcodeImg");
	//获取图形验证码
//	changeCode();
//	fcodeImg.addEventListener('click', function(event) {
//		changeCode();
//	});
	var accountBox = document.getElementById('phonenumber');
	var getchecknum = document.getElementById('get-checknum');
	var pagenum = document.getElementById('pagenum');
	var reg_password = document.getElementById('password');
	var checknum = document.getElementById('checknum');
	var mhide = document.getElementById('hide');
	var msend = document.getElementById('sendMail');
	var change = true;
	
	mhide.addEventListener('tap', function(event) {
		if(change) {
			mhide.src = '../../img/login/btn_eye_on@3x.png';
			reg_password.type = 'email';
			change = false;
		} else {
			mhide.src = '../../img/login/btn_eye@3x.png';
			reg_password.type = 'password';
			change = true;
		}
	});
//	获取验证码点击变色
	getchecknum.addEventListener('touchstart', function(event) {
		getchecknum.style.background = '#F0AD4E'
	});
	getchecknum.addEventListener('touchend', function(event) {
		getchecknum.style.background = '#F26100'
	});
	getchecknum.addEventListener('tap', function(event) {
		var network = true;
		
		if(network) {
			if(accountBox == "") {
				mui.toast("手机号不能为空");
				return;
			}
			var check_phone_number = /^1([38]\d|4[57]|5[0-35-9]|7[06-8]|8[89])\d{8}$/;
			if(accountBox.value.length == 0) {
				mui.toast("手机号不能为空");
				return;
			}
			if(accountBox.value.length != 11) {
				mui.toast("请输入有效的手机号！");
				return;
			}
			if(!accountBox.value.match(check_phone_number)) {
				mui.toast("请输入有效的手机号！");
				return;
			}
		}
		$.ajax({
			
			url:httpAdress + '/api/user/getSMSCode',
			contentType: "application/json; charset=utf-8",
	    dataType: 'jsonp',
	    jsonp: "callback",
	     jsonpCallback: "successCallback",
			type: 'get',
			//			url: strurl,
			data: {
				'phone': accountBox.value,
				'type': 2
//				'validcode': pagenum.value
			},
			success: function(data) {
				mtime(getchecknum);
				mui.toast(data.msg);
			},
			error: function(error) {
				mui.toast("获取信息失败，请重试！");
			}
		});

	})
	msend.addEventListener('tap', function(event) {
		var network = true;
		
		if(network) {
			if(accountBox == "") {
				mui.toast("手机号不能为空");
				return;
			}

			var check_phone_number = /^1([38]\d|4[57]|5[0-35-9]|7[06-8]|8[89])\d{8}$/;
			if(accountBox.value.length == 0) {
				mui.toast("手机号不能为空");
				return;
			}
			if(accountBox.value.length != 11) {
				mui.toast("请输入有效的手机号！");
				return;
			}
			if(!accountBox.value.match(check_phone_number)) {
				mui.toast("请输入有效的手机号！");
				return;
			}
		}
		$.ajax({
			type: 'get',
			url: httpAdress + '/api/user/resetpasswd',
			data: {
				'phone': accountBox.value,
				'passwd': reg_password.value,
                 'checknum':checknum.value,
				'validcode': 0
			},
			contentType: "application/json; charset=utf-8",
			dataType: 'jsonp',
			jsonp: "callback",
			jsonpCallback: "successCallback",
			success: function(data) {
				mui.toast(data.msg);
				if(data.status == 1) {
					localStorage.setItem("userid", data.userid);
                        localStorage.setItem("user", accountBox.value);
					document.location.href = '../../HTML/my/my.html';
				}
			},
			error: function(error) {
				mui.toast("数据提交失败，请重试！");
			}
		});

	});
